/**
 * [219] 存在重复元素 II
 *
 * @format
 * @lc app=leetcode.cn id=219 lang=javascript
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @param {number} k
 * @return {boolean}
 */
var containsNearbyDuplicate = function (nums, k) {
    const dict = {}
    for (let i = 0; i < nums.length; i++) {
        if (i - dict[nums[i]] <= k) return true
        dict[nums[i]] = i
    }
    return false
}
// @lc code=end
